<?php

// This file contains all the classes for certain uses on the site

class database {
   function database($server, $username, $password, $database=db_database){
     $this->connection = mysql_connect($server, $username, $password);
     if (!$this->connection || !mysql_select_db($database, $this->connection)) {
       return false;
     } else {
       return true;
     }
   }
   function numRows($result)
   {
   	 return count($result[0])>0?count($result):1;
   }
   function query($sql,$queryType=1,$db=db_database) {
     if($this->current_db()!=$db)
       mysql_select_db($db,$this->connection);
     $query = mysql_query($sql, $this->connection);
	if(!$query)
	{
		return 0;
	}
	else
	{
		$x=0;
     	while($row = mysql_fetch_array($query,$queryType)) {
     		$return[$x] = $row;
			//echo $return[$x];
	    	$x++;
     	}
	 mysql_free_result($query);
	 if(count($return)==1)
	 {
	 	$return=$return[0];
	 }
     return $return;
	}
   }
   function current_db() {
     $r = mysql_query("SELECT DATABASE()") or die(mysql_error());
     return mysql_result($r,0);
   }
   function getMemberOfGroup($uid,$group)
   {
   		/*echo "SELECT group_text FROM groups_members LEFT JOIN
			groups ON groups.group_id=groups_members.group_id
			WHERE UID=$uid";*/
		$result=$this->query("SELECT group_text FROM groups_members LEFT JOIN
			groups ON groups.group_id=groups_members.group_id
			WHERE UID=$uid",2);
		//echo $uid;
		//echo "True:".true." False:".false." - ";
		if(!$result)
			return false;
		foreach($result as $array)
		{
//			echo $array;
//			echo $array[0];//==='Developers';
			if (count($result)>1?$array[0]==='Developers':$array==='Developers')
			{
				//echo "true was hit";
				return true;
//				exit();
			}
		}
	}
	function executeSQL($query)
	{
		mysql_unbuffered_query($query);
		return mysql_affected_rows();
	}
}
?>